package com.itheima.health.controller;

import com.itheima.health.entity.QueryPageBean;
import com.itheima.health.entity.Result;
import com.itheima.health.pojo.Permission;
import com.itheima.health.service.PermissionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(tags = "权限模块管理")
@RequestMapping("permission")
public class PermissionController {

    @Reference
    private PermissionService permissionService;

    @GetMapping("findAll")
    @ApiOperation(value = "查询所有",notes = "查询所有权限列表信息")
    public Result findAll(){
        return new Result(permissionService.list());
    }

    @PostMapping("findpage")
    @ApiOperation(value = "分页查询",notes = "分页查询权限列表信息")
    public Result findPage(@RequestBody QueryPageBean queryPageBean){
        return new Result(permissionService.findPage(queryPageBean));
    }

    @PostMapping("saveOrUpdate")
    @ApiOperation(value = "添加或更新权限",notes = "带id过来就更新权限，不带id过来就是添加权限功能")
    public Result saveOrUpdate(@RequestBody Permission permission) {
        Boolean flag = permissionService.saveOrUpdate(permission);
        return new Result(flag);
    }

    @DeleteMapping("deleteById/{id}")
    @ApiOperation(value = "删除权限",notes = "删除权限功能")
    public Result deleteById(@PathVariable("id") int id){
        Boolean flag = permissionService.deleteById(id);
        return new Result(flag);
    }

}
